package com.wangyuan.demo.mapper;

import com.wangyuan.demo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户数据访问层
 *
 * @author Albert
 * @date 2025-06-23 21:42:54
 * @return
 */
@Mapper
public interface UserMapper {

    /**
     * 保存用户
     *
     * @param user
     * @return
     */
    @Insert("insert into t_user values(#{id},#{username},#{realname},#{password},#{sex})")
    void save(User user);

    /**
     * 根据用户名和密码查询用户
     *
     * @param username
     * @param password
     * @return User
     */
    @Select("select * from t_user where username = #{username} and password = #{password}")
    User findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);

    /**
     * 根据用户名查询用户
     *
     * @param username
     * @return User
     */
    @Select("select * from t_user where username = #{username}")
    User findByUsername(String username);

}